define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/example/redislock/redislock.js'
], function (require, exports) {
  // page加载完成后调用ready方法
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: '#redisLockDemo',
      data: {
        account: {
          accountId: '6221001100',
          amount: 1000,
          isSleep: false
        },
        tableData: [],
        transfUrl: backend.mycatService + '/api/redislock/trans',
        releaseUrl: backend.mycatService + '/api/redislock/release',
        refreshUrl: backend.mycatService + '/api/redislock/query'
      },
      methods: {
        transf: function () {
          var me = this;
          var myform = me.$refs.form0;

          myform.validate(function (valid) {
            var commitdata;
            commitdata = {
              accountId: me.account.accountId,
              amount: me.account.amount
            };

            if (valid) {
              var comitData = me.account;
              yufp.service.request({
                url: me.transfUrl,
                method: 'POST',
                data: commitdata,
                timeout: 600000,
                callback: function (code, message, response) {
                  if (response.code == 0) {
                    me.$message({ message: me.$t('redislock.dkcg'), type: 'success' });
                    me.refresh();
                  } else {
                    me.$message({ message: me.$t('redislock.dksb'), type: 'error' });
                  }
                }
              });
            } else {
              me.$message({ message: me.$t('redislock.qjcsrxsfhf'), type: 'warning' });
              return false;
            }
          });
        },
        release: function () {
          var me = this;
          var myform = me.$refs.form0;

          myform.validate(function (valid) {
            var commitdata;
            commitdata = {
              accountId: me.account.accountId,
              amount: me.account.amount
            };

            if (valid) {
              var comitData = me.account;
              yufp.service.request({
                url: me.releaseUrl,
                method: 'POST',
                data: commitdata,
                timeout: 600000,
                callback: function (code, message, response) {
                  if (response.code == 0) {
                    me.$message({ message: me.$t('redislock.qxcg'), type: 'success' });
                    me.refresh();
                  } else {
                    me.$message({ message: me.$t('redislock.qxsb'), type: 'error' });
                  }
                }
              });
            } else {
              me.$message({ message: me.$t('redislock.qjcsrxsfhf'), type: 'warning' });
              return false;
            }
          });
        },
        refresh: function () {
          var me = this;
          var accountId = me.account.accountId;

          yufp.service.request({
            url: me.refreshUrl + '?accountId=' + accountId,
            method: 'GET',
            callback: function (code, message, response) {
              if (response) {
                var data = {
                  accountId: accountId,
                  needtime: response.data.needtime,
                  systime: response.data.systime
                };
                me.tableData = [data];
              } else {
                me.tableData = [];
              }
            }
          });
        }
      }
    });
  };

  // 消息处理
  exports.onmessage = function (type, message) {

  };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {

  };
});
